package com.lanou3g.ptp.utils;

import com.github.pagehelper.PageInfo;

import java.util.HashMap;

public class PtpResultUtils {

    private static final int DEFAULT_SUCCESS_CODE = 200;
    private static final String DEFAULT_SUCCESS_MESSAGE = "ok";
    private static final String DEFAULT_ERROR_MESSAGE = "error";

    public static PtpResult ok(Object data) {
        PtpResult k12Result = ok();
        k12Result.setData(data);
        return k12Result;
    }

    public static PtpResult ok(PageInfo page) {
        PtpResult k12Result = ok();
        k12Result.setData(page.getList());
        k12Result.setPaging(new HashMap<String, Object>());
        k12Result.getPaging().put("page", page.getPageNum());
        k12Result.getPaging().put("size", page.getPageSize());
        k12Result.getPaging().put("total", page.getTotal());
        return k12Result;
    }

    public static PtpResult ok() {
        PtpResult k12Result = new PtpResult();
        k12Result.setCode(DEFAULT_SUCCESS_CODE);
        k12Result.setMessage(DEFAULT_SUCCESS_MESSAGE);
        return k12Result;
    }

    public static PtpResult error(int code) {
        PtpResult k12Result = new PtpResult();
        k12Result.setCode(code);
        k12Result.setMessage(DEFAULT_ERROR_MESSAGE);
        return k12Result;
    }

    public static PtpResult error(int code, String message) {
        PtpResult k12Result = new PtpResult();
        k12Result.setCode(code);
        k12Result.setMessage(message);
        return k12Result;
    }

}
